/*
 * This file is part of ddesktop: remote desktop system for iPad 
 *
 * Copyright (C) 2010 Kazuhiro Satoh
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. if not, see <http://www.gnu.org/licenses/>.
 */


#pragma once
#pragma unmanaged


namespace DDesktopServer
{

#define EVENT_QUEUE_SIZE 256

	class UIEventHandler
	{
	private:
		struct Event{
			int owner;
			int type;
			int param1;
			int param2;
			bool canceled;
		};

		class EventQueue{
		private:
			int m_read_pt;
			int m_write_pt;

			Event m_queue[EVENT_QUEUE_SIZE];

		public:
			EventQueue(void);
			~EventQueue();
			bool IsEmpty(void) const;
			bool IsFull(void) const;
			int Remain(void) const;
			int Count(void) const;
			void IncReadPt(void);
			void IncWritePt(void);

			bool Push(int owner, int type, int param1, int param2);
			Event* GetFront(void);
			Event* GetLast(void);
		};

		EventQueue m_event_queue;
		EventQueue m_mouse_move_event_queue;
		EventQueue m_mouse_wheel_event_queue;
		EventQueue m_window_move_event_queue;
		EventQueue m_window_resize_event_queue;

		bool ExecOneEvent(Event& e);
	public:

		UIEventHandler(void);
		~UIEventHandler();

		bool AddEvent(int type, int owner, int param1, int param2);
		bool Exec(int frame_ct);
	};
}

#pragma managed
